//
//  FirDetailTableViewCell.m
//  Protect -A
//
//  Created by 付剑英 on 16/6/21.
//  Copyright © 2016年 付剑英. All rights reserved.
//

#import "FirDetailTableViewCell.h"

#import <Masonry.h>
#import <UIImageView+WebCache.h>

@interface FirDetailTableViewCell ()

@end


@implementation FirDetailTableViewCell

#pragma mark - ------------ 内存管理 ---------------
-(void)dealloc{
    [_imgPhoto release];
    [_labelname release];
    [_labelPrice release];
    [_labelKuaidi release];
    [super dealloc];
}



#pragma mark - ------------ 初始化 --------------

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self create];
    }
    return self;

}
#pragma mark - ------------ 创建 ---------------

-(void)create{
    
    self.imgPhoto = [[baseImageView alloc]init];
    [self.contentView addSubview:self.imgPhoto];
    
    self.labelname = [[baseLabel alloc]init];
    [self.contentView addSubview:self.labelname];
    
    self.labelPrice = [[baseLabel alloc]init];
    [self.contentView addSubview:self.labelPrice];
    
    self.labelKuaidi = [[baseLabel alloc]init];
    [self.contentView addSubview:self.labelKuaidi];
    
    self.imgKuaidi = [[baseImageView alloc]init];
    [self.contentView addSubview:_imgKuaidi];

    [_labelKuaidi release];
    [_labelPrice  release];
    [_labelname   release];
    [_imgPhoto    release];
//        _imgPhoto.backgroundColor = [UIColor orangeColor];
//        _labelname.backgroundColor = [UIColor grayColor];
//    
//        _labelPrice.backgroundColor = [UIColor blueColor];
//        _labelKuaidi.backgroundColor = [UIColor yellowColor];
//        _imgKuaidi.backgroundColor = [UIColor redColor];
    
}



#pragma mark - ------------ 布局 ---------------

-(void)layoutSubviews{
    
    [super layoutSubviews];
    [_imgPhoto mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.mas_equalTo(self.contentView).offset(10);
        
        make.bottom.mas_equalTo(self.contentView).offset(-10);
        
        make.width.mas_equalTo(self.contentView.frame.size.width * 1/2 - 30);
    }];
    
    [_labelname mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.contentView).offset(10);
        make.right.mas_equalTo(self.contentView).offset(-10);
        make.left.mas_equalTo(_imgPhoto.mas_right).offset(10);
        make.bottom.mas_equalTo(_labelPrice.mas_top).offset(0);
        make.height.mas_equalTo(70);
    }];
    
    [_labelPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self.contentView).offset(-15);
        make.width.mas_equalTo(70);
        make.bottom.mas_equalTo(_labelKuaidi.mas_top).offset(-5);
        make.height.mas_equalTo(30);
    }];
    [_imgKuaidi mas_makeConstraints:^(MASConstraintMaker *make) {
        
        // make.left.mas_equalTo(_imgPhoto.mas_right).offset(10);
        make.top.mas_equalTo(_labelPrice.mas_bottom).offset(5);
        make.bottom.mas_equalTo(_imgPhoto);
        make.right.mas_equalTo(_labelKuaidi.mas_left).offset(0);
        make.width.mas_equalTo(30);
    }];
    
    
    [_labelKuaidi mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self.contentView).offset(-15);
        make.width.mas_equalTo(40);
        
        make.bottom.mas_equalTo(_imgPhoto);

    }];
}

#pragma mark - ------------ 重写model的set方法 ---------------

-(void)setModel:(ModelOfFirst *)model{

    
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    [_imgPhoto sd_setImageWithURL:[NSURL URLWithString:model.product_image] ];
    
    _labelname.text = model.name;
    _labelname.font = [UIFont systemFontOfSize:15];
    _labelname.numberOfLines = 0;
    
    NSInteger i = model.price.integerValue / 100;
    
    NSString *str = [NSString stringWithFormat:@"%ld", (long)i];
    _labelPrice.text = [NSString stringWithFormat:@"%@%@/%@", str, @"元", model.entity_name];
    _labelPrice.textColor = [UIColor redColor];
    _labelPrice.textAlignment = NSTextAlignmentRight;
    _labelPrice.font = [UIFont systemFontOfSize:15];
    
    _imgKuaidi.image = [UIImage imageNamed:@"kk"];
    _labelKuaidi.text = [model.stunt substringToIndex:2];
    
    _labelKuaidi.textAlignment = NSTextAlignmentCenter;
    _labelKuaidi.font = [UIFont systemFontOfSize:15];
    _labelKuaidi.textColor = [UIColor lightGrayColor];


}






@end
